package A;

public class Test_12 {
    public static void main(String[] args) {
        String[][] all = {
                {"张三","37","89","5"},
                {"李四","95","41","79"},
                {"王五","60","84","29"},
                {"赵六","87","46","86"}
        };
        //1.定义方法 printMathScore 打印所有同学数学成绩
        System.out.print("数学成绩：");
        for (String[] strings : all) {
            System.out.print(strings[2]+" ");
        }
        System.out.println();
        //2.定义方法 getCountMathScore   获取所有同学数学成绩的总和
        System.out.print("数学成绩总和：");
        int sumMath = 0;
        for (String[] strings : all) {
            sumMath += Integer.parseInt(strings[2]);
        }
        System.out.print(sumMath);
        System.out.println();
        //3.定义方法 getAvgMathScore  获取所有同学数学成绩的平均分
        int avgMath = sumMath / all.length;
        System.out.println("数学成绩平均分：" + avgMath);
        //4.定义方法 getAvgName     获取所有数学成绩超过平均分的人名
        System.out.print("数学成绩超过平均分的人：");
        int count = 0;
        for (String[] strings : all) {
            if (Integer.parseInt(strings[2]) > avgMath) {
                System.out.print(strings[0]+" ");
                count++;
            }
        }
        System.out.println();
        //5.定义方法 getAvgCount 获取所有数学成绩高过平均分的人数
        System.out.println("数学成绩超过平均分的人数为：" + count);
        //找到平均成绩最高的学科
        int[] avgArr = new int[3];
        for (String[] strings : all) {
            avgArr[0] += Integer.parseInt(strings[1]);
            avgArr[1] += Integer.parseInt(strings[2]);
            avgArr[2] += Integer.parseInt(strings[3]);
        }
        for (int i = 0; i < avgArr.length; i++) {
            avgArr[i] /= all.length;
        }
        int Avgmax = avgArr[0];
        for (int i : avgArr) {
            Math.max(Avgmax, i);
        }
        System.out.print("均成绩最高的学科：");
        int num = 0;
        for (int i = 0; i < avgArr.length; i++) {
            if (avgArr[i] == Avgmax) {
                num = i+1;
                switch (i) {
                    case 0:
                        System.out.println("语文");
                        break;
                    case 1:
                        System.out.println("数学");
                        break;
                    case 2:
                        System.out.println("英语");
                        break;
                }
            }
        }
        //获取该学科前三名同学的姓名
        int min = Integer.parseInt(all[0][num]);
        for (String[] strings : all) {
            Math.min(min, Integer.parseInt(strings[num]));
        }
        System.out.print("前三名的同学：");
        for (String[] strings : all) {
            if (Integer.parseInt(strings[num]) != min) {
                System.out.print(strings[0]+" ");
            }
        }
        System.out.println();
        //请找出不及格的科数小于等于1门的同学，且总成绩大于180分
        System.out.print("不及格的科数小于等于1门的同学:");
        for (String[] strings : all) {
            count = 0;
            for (int i = 1; i < strings.length; i++) {
                if (Integer.parseInt(strings[i]) < 60) {
                    count++;
                }
            }
            if (count <= 1) {
                System.out.print(strings[0]+" ");
            }
        }
    }
}
